package com.day1;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;

import org.dom4j.io.SAXReader;

public class Test1 {
    public static void main(String[] args) throws DocumentException{
        SAXReader reader=new SAXReader();
        //把xml文档读取,获取document
        Document document = reader.read(Test1.class.getClassLoader().getResourceAsStream("a.xml"));
        //获取根节点
        Element rootElement = document.getRootElement();
        String name = rootElement.getName();
        String text = rootElement.getText();
        System.out.println("name="+name);
        System.out.println("text="+text);
        //获取一个节点
        Element namenode= (Element) rootElement.selectSingleNode("stu//age");
        //节点传输内容用gettext获取
        String text1 = namenode.getText();
        System.out.println("text="+text1);

        String hobby = namenode.attributeValue("hobby");
        System.out.println("hobby="+hobby);

    }
}
